package com.heima.wemedia.controller.v2;


import com.heima.model.common.dtos.PageSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RequestMapping("/api/v1/channel")
@RestController
public class ChannelContoller {
    @Autowired
    private WmChannelService wmChannelService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody PageSensitive pageSensitive){
        ResponseResult result = wmChannelService.Channelist(pageSensitive);
        return result;
    }
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        WmChannel wmChanne= new WmChannel();
        wmChanne.setDescription(wmChannel.getDescription());
        wmChanne.setId(wmChannel.getId());
        wmChanne.setIsDefault(true);
        wmChanne.setOrd(wmChannel.getOrd());
        wmChanne.setStatus(wmChannel.getStatus());
        wmChanne.setName(wmChannel.getName());
        wmChannelService.updateById(wmChanne);
        return ResponseResult.okResult("ok");
    }
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        wmChannel.setIsDefault(true);
        wmChannel.setCreatedTime(new Date());
        wmChannelService.save(wmChannel);
        return ResponseResult.okResult("ok");
    }
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Long id){
        wmChannelService.removeById(id);
        return ResponseResult.okResult("ok");
    }

}
